<base href="/"> breaks SVG IRIs and element CSS URLs #1224
Comments
I had this same problem which unfortunately took me way more than 30 mins to realize what the cause was and ended up answering my own question in SO. I changed the SVG marker paths to the absolute ones, but I have to agree that it is not a robust workaround. |
@0x24a537r9 and @pgrodrigues thanks for the feedback. |
I'm happy to start a PR with guidance from someone more familiar with the codebase. I suspect that I would only need to change the paths in Given how far-reaching something like |
Slight complication... when I try removing the
Some Googling lead me to this Angular doc, which recommends using relative URLs with a
but that
Is IE9 even in MEAN.JS's intended support profile? Thoughts on whether we should still remove the Also, as an aside, it looks like there are a few other references that need updating outside of |
Ok, I went ahead and started PR #1230, manually updating all references I found via:
This got me most of the way there, and a few more manual tweaks revealed in manual testing got me to the point where everything seems to work as before in a local demo. All the server and e2e tests work, but unfortunately I'm having trouble with the client tests, where a large number fail before even getting to the tests'
All of the articles and chat controller tests fail with an unexpected request to |
@codydaig, @rhutchison what do you think? |
@0x24a537r9 seems that |
Can it be we need something similar to fix the tests for this pr #1207 ? Very same fail:
|
@trendzetter i'm not sure if you read my comments. PhantomJS 1.x series DOESN'T SUPPORT Function.prototype.bind.apply I have wrote this about 1 million times. If we want to see out tests doesn't fail. We have to DO : ( I will not write again these lines this will be my last writing about this Function.prototype.bind.apply ) BUT These 2 are just serverside test falsepossitives so it is not this PRs problems |
@trendzetter I don't believe your issue is in any way related to this one--the errors are completely different except that they both involve Update: unfortunately I haven't had time yet after work to try |
Hm, unfortunately neither @lirantal am I correct in assuming that you thought the failure might be related to I'll continue trying to debug. |
That's what I thought of but I hadn't done any work to investigate that path. |
I've also been looking for a solution to this. So far I've been able to get rid of errors about unexpected beforeEach(module(function($urlRouterProvider) {
$urlRouterProvider.deferIntercept();
// Tested, no dice:
//$urlRouterProvider.otherwise(function(){return false;});
})); But that will break tests testing Reading: |
If you think about the components that cause the problem:
none of these are meanjs specific and point more toward AngularJS itself. Googling: "angular $location base url svg" we find that the angular community have looked into it They've introduced a way to use html5mode without requiring a base path. This fixes issues with the SVG path however cuts support for browsers which do not have support for history push. However from further searches I was able to find: http://stackoverflow.com/questions/19742805/angular-and-svg-filters Which should fix the problem by putting absolute references into the SVG (hurdle identified as bullet pt 2 in @0x24a537r9 comment above). It may be unfeasible to edit generated SVG by hand to take advantage of this however a gulp task could automate this process allowing both SVG and HTML5mode support. The only downside would be the 2 SVG's with the same ID problem (bullet 3). Still, two ways to get around the problem with minimal change meanjs or svg give us options. |
@0x24a537r9 have you looked at a gulp task to do this? |
@Wuntenn would you like to complete the work in this issue and relevant PR that is open (some tests fail there)? |
Sure. Gimmie a sec - It should be a one liner (assuming it works as intended) |
Using fix specified here: angular/angular.js#8934 (comment) Fixes meanjs#1224, Fixes meanjs#1230
@meanjs/contributors anybody wishes to take a look here? |
Unfortunately, the
<base href="/">
tag inmodules/core/server/views/layout.server.view.html
breaks SVG IRIs and element CSS URLs.For those very reasonably unsure what I'm referring to:
url(#myElement)
, used throughout SVGs for referencing other elements usually defined in<defs>
tags. They are the only way to do a large number of things in SVGs including filters/manipulations, text paths, marker-start/-mid/-end (the way to make lines into arrows). The SVG spec 25 different SVG elements that can use IRIs--many of which only work with IRIs.mask
,clip-path
, andfilter
. These only work with relative URLs.The problem arises because, as mentioned in this article,
<base href="/">
will apply to all URL/IRIs in the document, including SVG IRIs and CSS URLs, which basically always reference a relative elementid
on the same page.Take this jsfiddle. Note the happy little triangle making the
<polyline>
into an arrow. Now look at the same fiddle with<base href="/">
. The arrow is no longer there because the IRI is now pointing incorrectly tohttps://jsfiddle.net/#Triangle
. You can tell by hovering over the blue-linkedurl("#Triangle")
style value in a Chrome style inspector on the<polyline>
.Unfortunately, there's only one way to override the
<base>
tag, and it only works in some situations and is pretty unpleasant. This jsfiddle demonstrates that you can instead use an absolute URL in the IRI, since<base>
tags only apply to relative URLs. Unfortunately, this has its downsides:id
in separate<svg>
elements on the same page and want to refer to them. For example, there is simply no way to make this jsfiddle work with a<base>
tag and absolute URLs, although it's clearly a valid use (since<svg>
elements kind of have their own documents, so the twoid
s aren't actually colliding).So what can we do? Well, in this StackOverflow question, a user asks how to override
<base>
, to which one user responded (back in 2012):It took me a good 30 mins of probing to get to the bottom of this, and I'd consider myself an expert with JS/HTML/CSS. For less experienced engineers, this could be a real tough bug to track down. And with the rise of visualization libraries like D3, SVG bugs like this are only going to come up more and more often. Since all of the page resources are controlled by a server-side template anyway, I think we should strongly consider prioritizing correctness over convenience and remove the
<base>
tag entirely, switching to fully-qualified path names for external resources.Sorry for the essay 😅 Thoughts?
The text was updated successfully, but these errors were encountered: